package com.jdd.modules.parkmonthly.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jdd.common.api.vo.Result;
import com.jdd.modules.parkmonthly.entity.MonthlyCarConfig;
import com.jdd.modules.parkmonthly.mapper.MonthlyCarConfigMapper;
import com.jdd.modules.parkmonthly.service.IMonthlyCarConfigService;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @Description: 车场月租配置信息
 * @Author: jdd
 * @Date:   2021-11-11
 * @Version: V1.0
 */
@Service
public class MonthlyCarConfigServiceImpl extends ServiceImpl<MonthlyCarConfigMapper, MonthlyCarConfig> implements IMonthlyCarConfigService {

    @Override
    public Result<MonthlyCarConfig> queryByParkCode(String parkCode) {
        Result<MonthlyCarConfig> result = new Result<>();
        LambdaQueryWrapper<MonthlyCarConfig> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MonthlyCarConfig::getParkCode, parkCode);
        List<MonthlyCarConfig> list = this.list(wrapper);
        MonthlyCarConfig monthlyCarConfig = null;
        if (CollectionUtils.isNotEmpty(list)) {
            monthlyCarConfig = list.get(0);
        }
        result.setSuccess(true);
        result.setMessage("查询成功");
        result.setResult(monthlyCarConfig);
        return result;
    }
    @Override
    public MonthlyCarConfig getInfoByParkCode(String parkCode){
        QueryWrapper<MonthlyCarConfig> queryWrapper = Wrappers.query();
        queryWrapper.eq("park_code", parkCode);
        queryWrapper.eq("del_flag", 0);
        List<MonthlyCarConfig> carConfigList = this.list(queryWrapper);
        if (CollectionUtils.isNotEmpty(carConfigList)) {
            return carConfigList.get(0);
        }
        return null;
    }
}
